package com.gaozhibo.mapper;

import com.gaozhibo.entity.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ArticleMapper {

    @Select("select * from article order by article_id desc limit 0,#{limit}")
    List<Article> listRecentArticle(Integer limit);

    @Select("select * from article where article_id = #{id}")
    Article getArticleById(Integer id);

    @Select("select * from article")
    List<Article> findAll();

    @Insert("insert into article values" + "(null,#{articleUserId},#{articleTitle}," + "#{articleContent},#{articleViewCount}," + "#{articleCommentCount},#{articleLikeCount}," + "#{articleIsComment},#{articleStatus}," + "#{articleOrder},#{articleUpdateTime}," + "#{articleCreateTime},#{articleSummary})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addArticle(Article article);

    @Delete("delete from article where article_id = #{id}")
    void deleteArticle(Integer id);

    @Update("update article set article_user_id =#{articleUserId},article_title = #{articleTitle}," + "article_content =#{articleContent},article_view_count =#{articleViewCount}," + "article_comment_count =#{articleCommentCount},article_like_count =#{articleLikeCount}," + "article_is_comment =#{articleIsComment},article_status = #{articleStatus}," + "article_order =#{articleOrder},article_update_time =#{articleUpdateTime}," + "article_create_time =#{articleCreateTime},article_summary = #{articleSummary} where article_id = #{articleId}")
    void updateArticle(Article article);
}
